package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.HContactInfoDto;
import com.crm.jdy.common.dto.WOutInfoDto;
import com.crm.jdy.common.pojo.HContactInfo;
import com.crm.jdy.common.pojo.WOutInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.HContactInfoService;
import com.crm.jdy.service.drp.WOutInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 通讯录信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "hContactInfo", description = "通讯录信息")
@RestController
@RequestMapping("/hContactInfo")
public class HContactInfoController{


    @Reference(version = "${service.version}", check = false)
    HContactInfoService wOutInfoService;

    @RateLimit()
    @ApiOperation("通讯录信息")
    @PostMapping("/seleteHContactInfo")
    public ResultVo seleteHContactInfo(@RequestBody HContactInfoDto wOutInfo){
        PageInfo<HContactInfo> list = wOutInfoService.seleteHContactInfo(wOutInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新通讯录信息")
    @PostMapping("/updateHContactInfo")
    public ResultVo updateHContactInfo(@ApiParam(value = "wOutInfo", required = true)
                                   @Validated @RequestBody HContactInfo wOutInfo){
        boolean index = wOutInfoService.updateHContactInfo(wOutInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加通讯录信息")
    @PostMapping("/addHContactInfo")
    public ResultVo addHContactInfo(@ApiParam(name = "wOutInfo", required = false)
                                @Validated @RequestBody HContactInfo wOutInfo){
        boolean list  = wOutInfoService.addHContactInfo(wOutInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除通讯录信息")
    @DeleteMapping("deleteHContactInfo/{canId}")
    public ResultVo deleteHContactInfo(@NotNull @ApiParam(name = "canId", value = "canId", required = true) @PathVariable String canId){
        boolean b = wOutInfoService.removeHContactInfo(canId);
        if(b){ 
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}